﻿
@{
    ViewData["Title"] = "选择投注";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/assets/css/jquery-ui.custom.min.css" rel="stylesheet" />
<link href="~/assets/css/jquery-ui.min.css" rel="stylesheet" />
<link href="~/assets/css/ace-rtl.min.css" rel="stylesheet" />

<style>
    .center {
        vertical-align: middle !important;
    }
    .right-result {
        color: red !important;
    }
    .select2-selection--single {
        height: 28px !important;
    }

    .selected {
        background-color: orange !important;
        border: solid;
        border-color: #bf3535;
    }
    .odd {
        width: 60px;
        cursor: pointer;
        padding: 0 !important;
    }
    .span-red {
        border-color: green !important;
    }

    .span-green {
        border-color: blue !important;
    }

    .span-blue {
        border-color: red !important;
        line-height: 100% !important;
    }

    .border-solid {
        /*width: calc(100% - 2px);
        height: calc(100% - 2px);*/
        display: inline-block;
        border: 1px solid;
        margin: 1px;
    }

    .border-double {
        /*width: calc(100% - 4px);
        height: calc(100% - 4px);*/
        display: inline-block;
        border: 2px solid;
        margin: 1px;
    }

    .default-span {
        /*width: calc(100% - 4px);
        height: calc(100% - 4px);*/
        display: inline-block;
        margin: 2px 2px 2px 2px !important;
        padding: 1px 6px 1px 6px;
        line-height: 100% !important;
    }

    .border-selected {
        border: 2px solid #6096f7 !important;
    }

    .tr-hover {
        background-color: #f7f7f7;
        opacity: 50;
    }

    .odd {
        cursor: pointer;
    }

    .winOdd, .loseOdd {
        cursor: pointer;
    }

    .checkOdd0 {
        background-color: #d6f2ac !important;
    }

    .checkOdd1 {
        background-color: #ddf58a !important;
    }

    .checkOdd2 {
        background-color: #cef659 !important;
    }

    .checkOdd3 {
        background-color: #a3f552 !important;
    }

    .background-tr-color {
        background-color: #e4f0fa;
    }

    .countColor1 {
        background-color: #bff5b7;
    }

    .countColor2 {
        background-color: #96b7fb;
    }


    .countColor3 {
        background-color: #4bfa21;
    }

    .table-mini tr th {
        padding: 0 3px 0 3px !important;
    }

    .table-mini tr td {
        padding: 0 3px 0 3px !important;
    }
</style>
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="~/Home/Index">首页</a>
        </li>
        <li>
            <a href="#">投注管理</a>
        </li>
        <li class="active">投注</li>
    </ul>

</div>
<p></p>
<div class="row">
    <div class="col-xs-12">
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-6" style="vertical-align:middle!important; padding:6px 0 0 0;">
                    <button class="btn btn-sm btn-white btn-primary" id="search-Btn" type="button">
                        受注赛程
                    </button>
                    <select id="GameNumberList"></select>
                </div>
                <div class="col-sm-6 " style="vertical-align:middle;text-align:right;padding:0 0 0 0;">


                    <div class="checkbox" style="display:inline-block">
                        <label>
                            <input name="form-field-checkbox" class="ace" id="singleMatchs" type="checkbox">
                            <span class="lbl">单关</span>
                        </label>
                    </div>
                    <div class="checkbox" style="display:inline-block">
                        <label>
                            <input name="form-field-checkbox" class="ace" id="sortChk" type="checkbox">
                            <span class="lbl">排序</span>
                        </label>
                    </div>
                    <div class="btn-group">
                        <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="false" data-toggle="dropdown">
                            筛选
                            <i class="ace-icon fa fa-angle-down icon-on-right"></i>
                        </button>
                        <div class="dropdown-menu" style="width:450px;padding:20px;">
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">SP</span>
                            </label>
                            <div id="SPDiv">
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="1.0">
                                    <span class="lbl">1.0-1.6</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="1.6">
                                    <span class="lbl">1.6-2.1</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="2.1">
                                    <span class="lbl">2.1-2.6</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="2.6">
                                    <span class="lbl">2.6-3.1</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;<br />
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="3.1">
                                    <span class="lbl">3.1-3.6</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="3.6">
                                    <span class="lbl">3.6-4.1</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="4.1">
                                    <span class="lbl">4.1-6.0</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="6.0">
                                    <span class="lbl">6.0-999.0</span>
                                </label>

                            </div>
                            <hr style="margin:4px;" />
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">日期</span>
                            </label>
                            <div id="DateDiv">

                            </div>
                            <hr style="margin:4px;" />
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">让球</span>
                            </label>

                            @*<label class="pos-rel pull-right" data-stopPropagation="true">
                                    <input type="checkbox" checked="checked" />
                                    <span class="lbl">全选</span>
                                </label>*@

                            <div id="RQDiv">

                            </div>

                            <hr style="margin:4px;" />
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">赛类</span>
                            </label>

                            <label class="pos-rel pull-right" data-stopPropagation="true">
                                <input type="checkbox" id="checkedAllLeagues" checked="checked" />
                                <span class="lbl">全选</span>
                            </label>

                            <div id="LeagueDiv">

                            </div>
                        </div>
                    </div>
                    <div class="btn-group">
                        <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="false" data-toggle="dropdown">
                            订制列
                            <i class="ace-icon fa fa-angle-down icon-on-right"></i>
                        </button>
                        <div class="dropdown-menu" id="columnDiv" style="width:300px;padding:20px;">
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="WuBaiID">
                                <span class="lbl">500ID</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="DateTime">
                                <span class="lbl">时间</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="Score">
                                <span class="lbl">比分</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="OddCount">
                                <span class="lbl">样本</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="YiJia">
                                <span class="lbl">欧赔概率溢价</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="NiHe">
                                <span class="lbl">拟合概率</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="CeLue">
                                <span class="lbl">策略系数</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="KeKao">
                                <span class="lbl">可靠性</span>
                            </label>

                            <hr style="margin:4px;" />
                            <button class="btn btn-sm btn-white btn-primary right" id="hiddenColumnBtn" type="button">
                                确定
                            </button>
                        </div>


                        @*<ul class="dropdown-menu">
                                <li>
                                    <a href="#">Action</a>
                                </li>
                                <li>
                                    <a href="#">Another action</a>
                                </li>
                                <li>
                                    <a href="#">Something else here</a>
                                </li>
                                <li class="divider"></li>
                                <li>
                                    <a href="#">Separated link</a>
                                </li>
                            </ul>*@
                    </div>
                </div>

            </div>
            <p />
            <div class="row">
                <table class="table table-mini table-condensed table-bordered no-footer" id="match-table" role="grid">
                    <thead id="matchData-thead">
                        <tr>
                            <th class="center" rowspan="2">序</th>
                            <th class="center WuBaiID" rowspan="2">500ID</th>
                            <th class="center " rowspan="2">ID</th>
                            <th class="center" rowspan="2">赛事</th>
                            <th class="center DateTime" rowspan="2">时间</th>
                            <th class="center" rowspan="2">主队</th>
                            <th class="center" rowspan="2">客队</th>
                            <th class="center Score" rowspan="2">比分</th>
                            <th class="center" rowspan="2">让球</th>
                            <th class="center" colspan="3">竞彩赔率</th>
                            <th class="center" rowspan="2">返还</th>
                            <th class="center" colspan="3">切片赔率</th>
                            <th class="center OddCount" rowspan="2">样本</th>
                            <th class="center YiJia" colspan="3">欧赔概率溢价</th>
                            <th class="center FanHuan" colspan="3">单项返还</th>
                            <th class="center NiHe" colspan="3">拟合概率</th>
                            <th class="center CeLue" colspan="3">策略系数</th>
                            <th class="center KeKao" colspan="3">可靠性</th>
                        </tr>
                        <tr>
                            <th class="center">胜</th>
                            <th class="center">平</th>
                            <th class="center">负</th>
                            <th class="center">胜</th>
                            <th class="center">平</th>
                            <th class="center">负</th>
                            <th class="center YiJia">胜</th>
                            <th class="center YiJia">平</th>
                            <th class="center YiJia">负</th>
                            <th class="center FanHuan">胜</th>
                            <th class="center FanHuan">平</th>
                            <th class="center FanHuan">负</th>
                            <th class="center NiHe">胜</th>
                            <th class="center NiHe">平</th>
                            <th class="center NiHe">负</th>

                            <th class="center CeLue">胜</th>
                            <th class="center CeLue">平</th>
                            <th class="center CeLue">负</th>
                            <th class="center KeKao">胜</th>
                            <th class="center KeKao">平</th>
                            <th class="center KeKao">负</th>


                        </tr>
                    </thead>
                    <tbody id="matchData-tbody"></tbody>

                </table>
            </div>


        </div>
        <div class="col-sm-3">

            <div class="tabbable">
                <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab" style="text-align:right">
                    <li class="active">
                        <a href="#fenbu" data-toggle="tab">

                            推荐
                        </a>
                    </li>

                    <li class="">
                        <a aria-expanded="true" href="#home" data-toggle="tab">
                            投注
                        </a>
                    </li>
                    <li class="">
                        <a aria-expanded="true" href="#ditu" data-toggle="tab">
                            地图
                        </a>
                    </li>
                </ul>
               
                <div class="btn-group" style="position:absolute;right:11px;top:14px;">
                    <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="true" data-toggle="dropdown">
                        标签
                        <i class="ace-icon fa fa-angle-down icon-on-left"></i>
                    </button>
                    <div class="dropdown-menu dropdown-info dropdown-menu-right" id="columnDiv" style="width:300px;padding:20px;">

                        <label class="pos-rel" data-stoppropagation="true"><input class="ace" value="-1" id="checkAllBookMark" checked="checked" type="checkbox"><span class="lbl">全选</span></label>
                        <label class="pos-rel pull-right" data-stoppropagation="true"><input class="ace" value="1" type="checkbox" id="liandong"><span class="lbl" style="color:peru">联动</span></label>

                        <hr style="margin:4px;" />
                        <div id="allMarks"></div>
                        <hr style="margin:4px;" />




                        <button class="btn btn-sm btn-white btn-primary pull-right" id="filterBookMark" type="button">
                            确定
                        </button>

                    </div>
                </div>


                <div class="tab-content">
                    <div id="fenbu" class="tab-pane fade in active" style="max-height:756px;height:756px; overflow:auto">
                        <table class="table table-condensed table-bordered">
                            <thead>
                                <tr>
                                    @*<th class="center">序号</th>*@
                                    <th class="center" style="width:70px;">ID</th>
                                    <th class="center"><span class="no-user-sp-caption">选择项</span></th>
                                    @*<th class="center"><span class="no-user-sp-caption">返还率</span></th>*@
                                    @*<th class="center"><span class="no-user-sp-caption">标签</span></th>*@
                                    <th class="center"><span class="no-user-sp-caption">SP</span></th>
                                    <th class="center"><span class="no-user-sp-caption">返还</span></th>
                                    <th class="center"><span class="no-user-sp-caption">备注</span></th>


                                    @*<th width="35"><a title="删除" id="clearList" href="javascript: void(0);">删除</a></th>*@
                                </tr>
                            </thead>
                            <tbody id="analyst_selected_list"></tbody>
                        </table>

                    </div>

                    <div id="ditu" class="tab-pane"  style="max-height:756px;height:756px; overflow:auto">

                        <table class="table table-condensed table-bordered" >
                            <thead>
                                <tr>
                                    @*<th class="center">序号</th>*@
                                    <th class="center">胜</th>
                                    <th class="center">平</th>
                                    <th class="center">负</th>
                                    <th class="center">胜</th>
                                    <th class="center">平</th>
                                    <th class="center">负</th>
                                    

                                </tr>
                            </thead>
                            <tbody id="selected_odd_list"></tbody>
                        </table>


                    </div>
                    <div class="tab-pane" id="home" style="max-height:756px;height:756px; overflow-y:auto;overflow-x:hidden;">


                        <div>
                            <table class="table table-condensed table-bordered">
                                <thead>
                                    <tr>
                                        <th class="center">编号</th>
                                        <th class="center hide" colspan="3">对阵</th>
                                        <th class="center"><span class="no-user-sp-caption">选择项</span></th>
                                        <th class="center"><span class="no-user-sp-caption">SP</span></th>
                                        <th class="center"><span class="no-user-sp-caption">返还</span></th>
                                        <th width="35"></th>
                                    </tr>
                                </thead>
                                <tbody id="selected_list"></tbody>
                            </table>
                            <div class="row col-sm-12">
                                <label class="col-sm-12 control-label" for="">过关方式</label>
                                <div class="col-sm-9 form-group" style="width:150px;">
                                    <div class="checkbox input-group-addon">
                                        <label>
                                            <input class="createOdd" type="checkbox" value="1">单关
                                        </label>
                                    </div>
                                    <div class="checkbox input-group-addon">
                                        <label>
                                            <input class="createOdd" type="checkbox" value="2">2串1
                                        </label>
                                    </div>
                                    <div class="checkbox input-group-addon">
                                        <label>
                                            <input class="createOdd" type="checkbox" value="3">3串1
                                        </label>
                                    </div>
                                </div>

                                <div class="pull-right col-sm-2 form-group">
                                    <button class="btn btn-white btn-sm btn-success" id="firstNextBtn" type="button">下一步</button>
                                </div>
                            </div>


                        </div>
                        <br>
                        <br>
                        <br>
                        
                        <div class="hide" id="oddDetails">
                            <div style="width:100%;height:1px;float:left;z-index:9999;position:relative">
                                <div id="disabled-panel" class="hide" style="width:100%;height:357px;z-index:9999;background-color:#e1dfdf; filter:alpha(Opacity=80);-moz-opacity:0.5;opacity: 0.5;"></div>

                            </div>

                            <table class="table table-condensed table-bordered">
                                <thead>
                                    <tr>
                                        <th class="center">序号</th>
                                        <th class="center">投注项</th>
                                        <th class="center"><span class="no-user-sp-caption">返还</span></th>
                                        <th class="center"><span class="no-user-sp-caption">sp</span></th>
                                        <th class="center"><span class="no-user-sp-caption">投注数</span></th>
                                        <th width="35"></th>
                                    </tr>
                                </thead>
                                <tbody id="selected_detailOdd_list"></tbody>
                            </table>
                            <div style="margin-top:-5px!important;">
                                <input id="oddArrString" type="hidden">

                                <div class="form-group col-sm-4" style="margin: 0 0 2px 0;">
                                    <div class="input-group">
                                        <input class="form-control" id="a1" type="text" placeholder="单倍金额">
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                                @*<div class="form-group col-sm-1"> &nbsp;</div>*@
                                <div class="form-group col-sm-4" style="margin: 0 0 2px 0;">
                                    <div class="input-group">
                                        <input class="form-control" id="a2" type="text" placeholder="倍数" value="1">
                                        <div class="input-group-addon">倍</div>
                                    </div>
                                </div>
                                @*<div class="form-group col-sm-1"> &nbsp;</div>*@
                                <div class="form-group col-sm-4" style="margin: 0 0 2px 0;">
                                    <div class="input-group">
                                        <input class="form-control" id="a3" type="text" readonly="readonly" placeholder="总计">
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>

                            <div style="margin-top:65px!important;">
                                <label>站点:</label>
                                <select style="width:70px;" id="selectSite"></select>
                                <label>账号:</label>
                                <select id="selectOddUser"></select>

                            </div><br />

                            <div style="margin-top:-5px!important;">
                                <label>标题:</label>
                                <input id="oddTitle" style="width:200px;" type="text" />
                            </div>


                            <div style="margin-top:5px!important;">
                                <label>说明:</label>

                                <label id="label-msg" style="margin-right:5px;">0</label>
                            </div>
                            <div>
                                <textarea id="oddDescption" style="width:100%" rows="3"></textarea>

                            </div>
                            <div style="margin-top:5px!important;">
                                <label>备注:</label>
                            </div>
                            <div>
                                <textarea id="oddRemark" style="width:100%" rows="3"></textarea>
                            </div>

                            <br />
                            <div class="text-right">

                                @*<label>操作人:</label>
            <select id="selectAppUser"></select>*@
                                <button class="btn btn-white btn-success btn-sm" id="SaveOdd" type="button">投注</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<div id="odd-detail-modal" class="hide">
    <div class="row">
        <div class="col-sm-12">
            <table class="table  table-bordered table-hover" role="grid" id="cutOddMatch-table">
                <thead>
                    <tr>
                        <th class="center">ID</th>
                        <th class="center">公司</th>
                        <th class="center">胜</th>
                        <th class="center">平</th>
                        <th class="center">负</th>
                        <th class="center">返还</th>
                        <th class="center">偏离</th>
                        <th class="center">时间</th>
                    </tr>
                </thead>
                <tbody id="cutOdds-data">
                    <tr>
                        <td class="center">115</td>
                        <td class="center">竞彩之家</td>
                        <td class="center">1.25</td>
                        <td class="center">2.8</td>
                        <td class="center">5.65</td>
                        <td class="center">91.2%</td>
                        <td class="center">3.4</td>
                        <td class="center">18-01-01 12:56:12</td>
                    </tr>

                </tbody>
            </table>
        </div>
    </div>
</div>




<script type="text/javascript">
    var siteType = "自身";
    var AllDistributionGraph = [];
    var AllMatchs = [];
    var AllAppUser = [];
    var defaultPayOut = 9200;
    var SelectedMatchs = [];
    var betDetailOdds = [];
    var AllBookMarks = [];
    var OddValueArr = [{ min: 1.0, max: 1.6 }, { min: 1.6, max: 2.1 }, { min: 2.1, max: 2.6 }, { min: 2.6, max: 3.1 }, { min: 3.1, max: 3.6 }, { min: 3.6, max: 4.1 }, { min: 4.1, max: 6.0 }, { min: 6.0, max: 999 }];
    var OddMoneyBoundary = 0;
    var AnalystSelectedMatchs = [];
    var SelectedResultObj =
        [
            { id: "1", text: "胜" },
            { id: "2", text: "平" },
            { id: "3", text: "负" },
            { id: "4", text: "让胜" },
            { id: "5", text: "让平" },
            { id: "6", text: "让负" }
        ];
    $(".dropdown-menu").on("click", "[data-stopPropagation]", function (e) {
        e.stopPropagation();
    });



    $(function () {
        $(document).attr("title", "投注");
        GetOddMoneyBoundary();
        GetAllIssues();
       
        GetAllBoomMarks();
        GetNoneChildrenSites();
        GetAllAppUser();
        $("#search-Btn").click(function () {
            GetRealTimeData();
        });
        $("#checkAllBookMark").change(function () {
            if ($(this).is(":checked")) {
                $("#allMarks .ace").prop("checked", true);
            } else {
                $("#allMarks .ace").removeAttr("checked");
            }
        });

        $("#GameNumberList").change(function () {
            var issue = $(this).val();
            GetMatchDataByIssue(issue);
        });

        $("#hiddenColumnBtn").click(function () {
            var c = $("#columnDiv input:checkbox");
            var checkedValue = [];
            var noCheckedValue = [];
            $.each(c, function (i, n) {
                if ($(n).is(":checked")) {
                    checkedValue.push($(n).val());
                } else {
                    noCheckedValue.push($(n).val());
                }
            });

            $.each(checkedValue, function (i, n) {
                $("." + n).show();
            });
            $.each(noCheckedValue, function (i, n) {
                $("." + n).hide();
            });


            $("#match-table").chromatable({
                width: "100%",
                height: "780px",
                scrolling: "yes"
            });
        });

        $("#singleMatchs").change(function () {
            var trs = $("#matchData-tbody tr");
            if ($(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("CanSingleBet");
                        if (date == "0") {
                            $(n).hide();
                        }
                    }
                });
            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        $(n).show();
                    }
                });
            }

            $("#match-table").chromatable({
                width: "100%",
                height: "780px",
                scrolling: "yes"
            });
        });

        $("#firstNextBtn").click(function () {

            var detailOdds = [];
            var guoguan = $("input.createOdd:checked");

            $("#disabled-panel").addClass("hide");
            $("#a1,#a2,#a3,#oddRemark,#oddTitle,#oddDescption").val("");
            $("#label-msg").html("0");
            $("#selected_detailOdd_list").empty();
            if (SelectedMatchs.Count() == 0) {
                layer.alert("请选择比赛投注项");
                return;
            }
            if (guoguan.length == 0) {
                layer.alert("请选择过关方式");
                return;
            }
            $.each(guoguan, function (i, n) {
                var value = parseInt($(n).val());
                if (value == 1) {
                    var odds = MakeBettingDanGuanDetails(SelectedMatchs);
                    detailOdds = detailOdds.concat(odds);
                } else if (value == 2) {
                    var odds = MakeBetting2X1Details(SelectedMatchs);
                    detailOdds = detailOdds.concat(odds);
                } else if (value == 3) {

                    var odds = MakeBetting3X1Details(SelectedMatchs);
                    detailOdds = detailOdds.concat(odds);
                }
            });
            betDetailOdds = new Array();
            $.each(detailOdds, function (i, n) {
                var sp = 1;
                var payReturn = 1;
                $.each(n, function (f, g) {
                    sp = sp * g.SelectedOdds;
                    payReturn = payReturn * (g.SelectedPayReturn / 100);
                });

                var bet = {
                    Index: i,
                    Checked: true,
                    Content: getContentString(n),
                    SP: sp.toFixed(2),
                    PayReturn: payReturn,
                    BetCount: 0,
                    BetDetailOddContents: n
                }
                betDetailOdds.push(bet);
            });
            WriteOddTableData();
            $("#oddDetails").removeClass("hide");

        });

        $("#sortChk").change(function () {
            var trs = $("#matchData-tbody tr");
            if ($(this).is(":checked")) {
                trs.sort(MatchSortCompareDesc());
                $("#matchData-tbody").empty();
                $("#matchData-tbody").append(trs);
            } else {
                trs.sort(trcompare(0));
                $("#matchData-tbody").empty().append(trs);
            }
        });
        $(document).delegate(".oddValueChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = parseFloat($(this).val());

            var valueModel = OddValueArr.FirstOrDefault(function (x) { return x.min == value; });
            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var oddValue = parseFloat($(n).children("td").eq(9).html());
                        if (oddValue >= valueModel.min && oddValue < valueModel.max) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var oddValue = parseFloat($(n).children("td").eq(9).html());
                        if (oddValue >= valueModel.min && oddValue < valueModel.max) {
                            $(n).show();
                        }
                    }
                });
            }
        });
        $(document).delegate(".DateChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = $(this).val();


            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("issue");
                        if (date == value) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var date = $(n).attr("issue");
                        if (date == value) {
                            $(n).show();
                        }
                    }
                });
            }
        });
        $(document).delegate(".RQChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = $(this).val();


            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("FixOdds");
                        if (date == value) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var date = $(n).attr("FixOdds");
                        if (date == value) {
                            $(n).show();
                        }
                    }
                });
            }
        });
        $(document).delegate(".LeagueChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = $(this).val();
            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("League");
                        if (date == value) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var date = $(n).attr("League");
                        if (date == value) {
                            $(n).show();
                        }
                    }
                });
            }
        });

        $("#checkedAllLeagues").change(function () {
            if ($(this).is(":checked")) {
                $(".LeagueChk").prop("checked", true);
            } else {
                $(".LeagueChk").removeAttr("checked");
            }
        });
        //$(document).delegate(".linkTo500", "click", function () {
        //    var matchId = $(this).attr("matchId");
        //    window.open("http://odds.500.com/fenxi/shuju-" + matchId + ".shtml");
        //    return false;
        //});

        $(document).delegate(".winOdd,.drawOdd,.loseOdd", "click", function () {
            $(this).toggleClass("selected");

            var matchId = parseInt($(this).attr("matchId"));
            var result = $(this).attr("result");
            var value = $(this).text();
            var payReturn = $(this).attr("payreturn");
            var fixOdd = $(this).attr("fixOdd");
            var bOddId = $(this).attr("bOddId");
            var chance = $(this).attr("chance");
            if ($(this).hasClass("selected")) {
                var tr = $("#selected_list tr[matchId='" + matchId + "']");

                var match = AllMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
                var odd = {
                    SelectedMatchId: matchId,
                    FixOdds: fixOdd,
                    WeekName: match.matchNumber,
                    SelectedResult: result,
                    SelectedOdds: parseFloat(value),
                    SelectedPayReturn: payReturn,
                    LotteryResults: -1
                };

                if (tr.length > 0) {
                    var span = $(tr).children("span.selectedResult[result='" + result + "']");
                    if (span.length == 0) {
                        $("#selected_list tr[matchId='" + matchId + "'] td:eq(4)").append('<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + matchId + '" result="' + result + '" bOddId="' + bOddId + '"  oddValue="' + value + '" chance="' + chance + '">' + SelectedResultObj.First(function (x) { return x.id == result }).text + '-' + value + '</span>');

                        var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
                        smatch.selectedOdds.push(odd);
                    } else {
                        $(span).remove();
                        $("#selected_list tr[matchId='" + matchId + "'] td:eq(4)").append('<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + matchId + '" result="' + result + '" bOddId="' + bOddId + '"  oddValue="' + value + '" chance="' + chance + '">' + SelectedResultObj.First(function (x) { return x.id == result }).text + '-' + value + '</span>');
                        var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
                        smatch.selectedOdds.FirstOrDefault(function (x) { return x.SelectedResult == result }).SelectedOdds = parseFloat(value);
                        smatch.selectedOdds.FirstOrDefault(function (x) { return x.SelectedResult == result }).SelectedPayReturn = payReturn;

                    }
                    var s = 0;
                    var chance = 0;
                    $.each($("#selected_list tr[matchId='" + matchId + "'] td:eq(4) span"), function (i, n) {
                        var odd = parseFloat($(n).attr("oddValue"));
                        var ca = parseFloat($(n).attr("chance"));
                        s += 1.0 / odd;
                        chance += ca;
                    });
                    var sp = Math.round(100.0 / s) / 100;
                    chance = Math.round(100 * sp * chance) / 100;
                    $("#selected_list tr[matchId='" + matchId + "'] td:eq(5)").html(sp);
                    $("#selected_list tr[matchId='" + matchId + "'] td:eq(6)").html(chance);

                } else {
                    var match = AllMatchs.FirstOrDefault(function (x) { return x.matchId == matchId; });
                    var ss = '';

                    ss += '<tr style="display: table-row;" matchId="' + matchId + '">';
                    ss += '<td class="center" >' + match.matchNumber + '</td >';
                    ss += '<td class="center hide">' + match.homeTeamName + '</td>';
                    ss += '<td class="center hide">VS</td>';
                    ss += '<td class="center hide">' + match.awayTeamName + '</td>';

                    ss += '<td class="center">';
                    ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + matchId + '" result="' + result + '" oddValue="' + value + '" bOddId="' + bOddId + '" chance="' + chance + '">' + SelectedResultObj.First(function (x) { return x.id == result }).text + '-' + value + '</span>';
                    ss += '  </td>';
                    ss += '<td class="center">' + value + '</td>';
                    ss += '  <td class="center">' + payReturn + '</td>';
                    ss += '  <td class="center"><a title="删除" href="#" matchId="' + matchId + '" class="deleteSelectedMatch" result="' + result + '"><i class="glyphicon glyphicon-remove"></i></a></td>';
                    ss += '  </tr >';

                    $("#selected_list").append(ss);
                    var smatch = {
                        matchId: matchId,
                        dan: false,
                        selectedOdds: []
                    };
                    smatch.selectedOdds.push(odd);
                    SelectedMatchs.push(smatch);
                }
            } else {
                var td = $("#selected_list tr[matchId='" + matchId + "'] td:eq(4)");
                $(td).children('span[matchId="' + matchId + '"][result="' + result + '"]').remove();

                if ($(td).children("span").length == 0) {
                    $(td).parent().remove();
                } else {
                    var s = 0;
                    var chance = 0;
                    $.each($("#selected_list tr[matchId='" + matchId + "'] td:eq(4) span"), function (i, n) {
                        var odd = parseFloat($(n).attr("oddValue"));
                        var ca = parseFloat($(n).attr("chance"));
                        s += 1.0 / odd;
                        chance += ca;
                    });
                    var sp = Math.round(100.0 / s) / 100;
                    var chance = Math.round(100 * sp * chance) / 100;
                    $("#selected_list tr[matchId='" + matchId + "'] td:eq(5)").html(sp);
                    $("#selected_list tr[matchId='" + matchId + "'] td:eq(6)").html(chance);
                }

                var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
                var odd = smatch.selectedOdds.FirstOrDefault(function (x) { return x.SelectedResult == result });
                smatch.selectedOdds.remove(odd);
                if (smatch.selectedOdds.length == 0) {
                    SelectedMatchs.remove(smatch);
                }
            }
        });

        $(document).delegate(".deleteSelectedMatch", "click", function () {
            var matchId = $(this).attr("matchId");
            $("#selected_list tr[matchId='" + matchId + "']").remove();
            $("#matchData-tbody tr[matchId='" + matchId + "'] td.winOdd,#matchData-tbody tr[matchId='" + matchId + "'] td.drawOdd,#matchData-tbody tr[matchId='" + matchId + "'] td.loseOdd").removeClass("selected");
            var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
            SelectedMatchs.remove(smatch);
            return false;
        });

        $(document).delegate("#a1", "input propertychange", function () {

            var money = parseInt($(this).val());
            var beishu = parseInt($("#a2").val());

            $("#a3").val(money * beishu);
            AverageCapital(money);
            WriteOddTableData();
        });

        $(document).delegate("#oddRemark", "input propertychange", function () {
            $("#label-msg").html($(this).val().length);
           
        });

        $(document).delegate("#a2", "input propertychange", function () {

            var money = parseInt($("#a1").val());
            var beishu = parseInt($("#a2").val());

            $("#a3").val(money * beishu);

        });
        $(document).delegate(".count", "input propertychange", function () {

            var count = 0;
            $.each($(".count"), function (i, m) {
                count += parseInt($(m).val());
            });
            $("#a1").val(count * 2);

            var beishu = parseInt($("#a2").val());
            var money = parseInt($("#a1").val());
            $("#a3").val(money * beishu);
        });

        $(document).delegate(".deleteCreatedOdd", "click", function () {
            var index = $(this).attr("index");
            $(this).parent().parent().remove();
            var odd = betDetailOdds.First(function (x) { return x.Index == index });
            betDetailOdds.remove(odd);
            return false;
        });

        $("#selectSite").change(function () {
            var siteId = $(this).val();
            $("#selectOddUser").empty();
            AjaxData("/OddUser/GetOddUserBySiteId", "siteId=" + siteId, "Get", $(this), function (d) {
                if (undefined != d && null != d) {
                    var ss = '';


                    var resultArray = d.data.sort(
                        function compareFunction(param1, param2) {
                            return param1.account.localeCompare(param2.account, "zh");
                        }
                    );

                    $.each(resultArray, function (i, n) {
                        if (i == 0) {
                            ss += '<option value="' + n.id + '" selected="selected">' + n.account + '</option>';
                        } else {
                            ss += '<option value="' + n.id + '">' + n.account + '</option>';
                        }
                    });
                    $("#selectOddUser").html(ss).select2({ width: 140 });
                }
            });
        });


        $("#SaveOdd").click(function () {
            var odd = GetMatchContents();

            if (OddMoneyBoundary > 0 && odd.OwnPurchaseMoney >= OddMoneyBoundary) {
                var isContains = true;
                $.each($("#matchData-tbody td.selected"), function (i, n) {
                    if (!$(n).find("span").hasClass("span-red") && !$(n).find("span").hasClass("span-blue") && !$(n).find("span").hasClass("span-green")) {
                        isContains = false;
                        return false;
                    }
                });
                if (!isContains) {
                    layer.alert("请选择分析师选择的比赛选项进行投注");
                    return;
                }
            }

            var postData = {
                odd: odd
            };
            AjaxData("/Odd/Add", postData, "POST", "", function (d) {
                if (undefined != d && null != d) {
                    if (d.success) {
                        layer.alert("投注成功");
                        $("#disabled-panel").css("height", $("#oddDetails").css("height"));
                        $("#disabled-panel").removeClass("hide");
                    } else {
                        layer.alert(d.message);
                    }
                }
            });
        });
        $("#filterBookMark").click(function () {
            var checkedBookMarks = $("#allMarks").find("input:checked");

            var marksArr = [];
            $.each(checkedBookMarks, function (i, n) {
                marksArr.push($(n).val());
            });
            var sMatchs = [];
            $.each(AnalystSelectedMatchs, function (i, n) {
                if (n.bookMarksString.length == 0) {
                    if (marksArr.contains("-1")) {
                        ck = true;
                    }

                } else {
                    var bks = n.bookMarksString.split(',');
                    var ck = false;
                    $.each(marksArr, function (j, k) {
                        if (bks.contains(k)) {
                            ck = true;
                            return true;
                        }
                    });
                }
                if (ck) {
                    sMatchs.push(n);
                }

            });

            $("#analyst_selected_list").empty();

           
            $(".span-red").removeClass("span-red");
            $(".span-green").removeClass("span-green");
            $(".span-blue").removeClass("span-blue");
            $(".border-solid").removeClass("border-solid");
            $(".border-double").removeClass("border-double");
            $.each(sMatchs, function (i, n) {

                var ss = '<tr style="display: table-row;" matchId="' + n.matchId + '">';
                ss += '<td class="center" >' + n.detailSelectedContentsList[0].weekName + '</td >';
                //ss += '<td class="center">' + match.cutPayOutRate + '</td>';
                ss += '<td class="center">';
                var cuser = AllAppUser.FirstOrDefault(function (x) { return x.id == n.createAppUserId });


                var bd = n.detailSelectedContentsList.Where(function (x) { return x.fixOdds == ""; });
                $.each(bd, function (j, k) {

                    ss += k.selectedOdds;
                    if (j < bd.length - 1) {
                        ss += '+';
                    } else {
                        ss += "<br/>";
                    }

                    var fselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                    var selector;
                    if (cuser.colorName == 1) {
                        selector = fselector.children("span");
                        selector.addClass("span-red");
                    } else if (cuser.colorName == 2) {
                        selector = fselector.children("span").children("span");
                        selector.addClass("span-green");
                    } else {
                        selector = fselector.children("span").children("span").children("span");
                        selector.addClass("span-blue");
                    }
                    if (k.goodLevel == 1) {
                        selector.addClass("border-solid");
                    } else {
                        selector.addClass("border-double");
                    }
                });

                var rd = n.detailSelectedContentsList.Where(function (x) { return x.fixOdds != ""; });
                $.each(rd, function (j, k) {
                  
                    ss += k.selectedOdds;
                    if (j < rd.length - 1) {
                        ss += '+';
                    }
                    
                    $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']").parent().show();

                    var pselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                    if (cuser.colorName == 1) {
                        selector = $(pselector).children("span");
                        selector.addClass("span-red");
                    } else if (cuser.colorName == 2) {
                        selector = $(pselector).children("span").children("span");
                        selector.addClass("span-green");

                    } else {
                        selector = $(pselector).children("span").children("span").children("span");
                        selector.addClass("span-blue");

                    }
                    if (k.goodLevel == 1) {
                        selector.addClass("border-solid");
                    } else {
                        selector.addClass("border-double");
                    }



                });
                ss += '</td>';
                ss += '<td class="center" >' + n.sp + '</td >';
                ss += '<td class="center" >' + n.resultChance + '</td >';
                //ss += '<td class="center">' + CreateBookMarkOption(n.bookMarksString) + '</td>';
                ss += '<td class="center" ><a href="#" title="' + n.remark + '">' + n.remark.substring(0,2) + '</a></td >';
                ss += '  </tr >';

                $("#analyst_selected_list").append(ss);

            });

            $("#liandong").trigger("change");


        });

        $("#liandong").change(function () {
            var trs = $("#matchData-tbody tr");
            if ($(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if ($(n).find("td.border-selected").length == 0) {
                        $(n).hide();
                    }
                });
            } else {
                $.each(trs, function (i, n) {

                    $(n).show();

                });
            }

            $("#match-table").chromatable({
                width: "100%",
                height: "780px",
                scrolling: "yes"
            });
        })

    });

    function WriteDetailContent(match, d) {
        var ss = '';
        if (undefined != d && null != d && d.length > 0) {

            var arr = [],arr1=[],arr2=[],arr3=[],arr4=[],arr5=[];
            ss += '<tr>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds=''] .winOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds=''] .drawOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds=''] .loseOdd").html() + '</td>';

            $.each(d, function (a, b) {
                if (null != b.betDetailOddList) {
                    $.each(b.betDetailOddList, function (i, n) {
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId  && x.selectedResult==1; }) > 0) {
                            arr.push(n);
                        }

                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId  && x.selectedResult == 2; }) > 0) {
                            arr1.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId  && x.selectedResult == 3; }) > 0) {
                            arr2.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId  && x.selectedResult == 4; }) > 0) {
                            arr3.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId  && x.selectedResult == 5; }) > 0) {
                            arr4.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 6; }) > 0) {
                            arr5.push(n);
                        }


                    });
                }
            });


            ss += '<td class="center">' + arr.Sum(function (x) { return x.betCount;}) + '</td>';
            ss += '<td class="center">' + arr1.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr2.Sum(function (x) { return x.betCount; }) + '</td>';


            ss += '</tr>';
            ss += '<tr>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds!=''] .winOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds!=''] .drawOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds!=''] .loseOdd").html() + '</td>';
            ss += '<td class="center">' + arr3.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr4.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr5.Sum(function (x) { return x.betCount; }) + '</td>';


            ss += '</tr>';
            ss += "<tr><td colspan='6'>";
            $.each(d, function (i, n) {

               
                $.each(n.betDetailOddList, function (j, k) {
                    var dOdd = k.betDetailOddContentsList.FirstOrDefault(function (x) { return x.selectedMatchId == match.matchId; });
                    if (null != dOdd) {
                        ss +=  n.createOddUserName;
                        ss += "&nbsp;&nbsp;&nbsp;&nbsp;" + GetContentString(k) + "";
                        ss += '<br/>';
                    }

                });
                
            });
            ss += "</td></tr>";
        }
        return ss;
    }

    function GetContentString(n) {
        var ss = "";
        var s = "";
        var pay = 1; var r = "";
        if (null != n.betDetailOddContentsList && n.betDetailOddContentsList.Count() > 0) {

            $.each(n.betDetailOddContentsList, function (j, k) {
                r += k.lotteryResults + "";
                pay = pay * k.selectedOdds;
                //if (k.fixOdds == "" || parseInt(k.fixOdds) == 0) {
                //    s += k.weekName + MatchResult.FirstOrDefault(function (x) { return x.id == k.selectedResult }).text;

                //} else {


                //}
                s += k.weekName + MatchResult.FirstOrDefault(function (x) { return x.id == k.selectedResult }).text;
                if (k.lotteryResults == "1") {

                    s += "<span class='red'>" + k.selectedOdds + "</span>";
                } else if (k.lotteryResults == "0") {
                    s += "<span class='blue'>" + k.selectedOdds + "</span>";
                } else {
                    s += k.selectedOdds;

                }
                if (j < n.betDetailOddContentsList.Count() - 1) {
                    s += '|';
                }
            });
        }

        if (r == '1' || r == "11" || r == "1-1" || r == "11-1" || r == "111") {
            ss += n.betCount + "倍<span class='red'>" + pay.toFixed(2) + " </span>" + s;

        } else if (r == "0" || r == '00' || r == '10' || r == '01' || r == '0-1' || r == '11'
            || r == '110' || r == '101' || r == '100' || r == '011' || r == '001' || r == '010' || r == '011'
            || r == '01-1' || r == '00-1' || r == '10-1' || r == '0-1-1'
        ) {
            ss += n.betCount + "倍<span class='blue'>" + pay.toFixed(2) + " </span>&nbsp;" + s;

        } else {
            ss += n.betCount + "倍" + pay.toFixed(2) + "&nbsp; " + s;

        }
        return ss;
    }


    function GetOddBySelectedMatchIds(ids) {

        $("#selected_odd_list").html("");
        var postData = {
            ids: ids
        }

        AjaxData("/Odd/GetOddBySelectedMatchIds", postData, "Post", "", function (d) {
            if (undefined != d && d.success) {
                var odds = d.data;
                var weekNames = AllMatchs.Select(function (x) { return x.matchNumber }).Distinct().OrderBy(function (x) { return x; });
                if (null != weekNames) {
                    var ss = '';
                    $.each(weekNames, function (i, n) {
                        var match = AllMatchs.FirstOrDefault(function (x) { return x.matchNumber == n; });
                        var odd = odds.Where(function (x) { return x.betDetailOddList.Count(function (y) { return y.betDetailOddContentsList.Count(function (z) { return z.selectedMatchId == match.matchId; }) > 0 }) > 0 });
                        if (odd.length > 0) {
                            ss += '<tr>';
                            ss += '<td colspan="6">' + n + "&nbsp;&nbsp;&nbsp;" + match.homeTeamName + ' VS ' + match.awayTeamName + '</td>';
                            ss += '</tr>';
                            ss += WriteDetailContent(match, odd);
                           
                        }

                    });

                    $("#selected_odd_list").html(ss);
                }
            }
        });
    }

    function GetAllBoomMarks() {

        $("#allMarks").empty();
        AjaxData("/BookMark/GetAllList", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                if (d.success) {
                    AllBookMarks = d.data;
                    var s = '<label class="pos-rel" data-stoppropagation="true"><input class="ace" value= "-1" type= "checkbox" checked="checked" ><span class="lbl">无标签</span></label >';
                    $.each(d.data, function (i, n) {
                        s += '<label class="pos-rel" data-stoppropagation="true"><input class="ace" value= "' + n.id + '" type= "checkbox" checked="checked" ><span class="lbl">' + n.markName + '</span></label >';
                    });
                    $("#allMarks").html(s);
                }
            }
        });
    }



    function GetOddMoneyBoundary() {
        AjaxData("/SystemConstant/GetOddMoneyBoundary", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                OddMoneyBoundary = d.data;
            }
        });
    }

    function GetMatchContents() {
        var saveOdd = {
            Id: -1,
            CreateTime: new Date().format("yyyy-MM-dd hh:mm:ss"),
            BespeakCutoffTime: new Date().format("yyyy-MM-dd hh:mm:ss"),
            DocumentaryCutoffTime: new Date().format("yyyy-MM-dd hh:mm:ss"),
            SiteId: $("#selectSite").val(),
            CreateOddUserId: $("#selectOddUser").val(),
            //AppUserId: $("#selectAppUser").val(),
            OwnPurchaseMoney: parseInt($("#a3").val()),
            DocumentaryUserCount: 0,
            DocumentaryMoney: 0,
            OwnPurchaseRebate: 0,
            DocumentaryRebate: 0,
            OwnBonus: 0,
            DocumentaryBonus: 0,
            EstimatedCommission: 0,
            ActualCommission: 0,
            ProfitAndLoss: 0,
            LotteryTime: new Date(),
            Result: -1,
            Divisor: parseInt($("#a2").val()),
            BetDetailOddList: [],
            OddSelectedMatchList: [],
            Remark: $("#oddRemark").val(),
            Descption: $("#oddDescption").val(),
            OrderString: '',
            Title:$("#oddTitle").val()
        };
        var row = $("#selected_detailOdd_list tr");
        $.each(row, function (i, n) {
            var index = $(n).children("td:eq(0)").html();

            var singleOdd = betDetailOdds.FirstOrDefault(function (x) { return x.Index == (parseInt(index) - 1) });

            var beishu = parseInt($("#a2").val());
            var rowData = {
                Id: -1,
                OddId: -1,
                BetCount: (parseInt($(n).find(".count").val()) * beishu),
                Remark: '',
                BetDetailOddContentsList: singleOdd.BetDetailOddContents
            };
            if (rowData.BetCount > 0) {
                saveOdd.BetDetailOddList.push(rowData);
            }
        });


        row = $("#selected_list tr");
        var smatchs = new Array();
        var lotteryTime = new Date();
        var issue = '';
        var num = '';
        var dTime = '';
        $.each(row, function (i, n) {
            //if (i == row.lenght - 1) { return true; }

            var matchId = parseInt($(n).attr("matchId"));
            var cmatch = AllMatchs.FirstOrDefault(function (x) { return x.matchId == matchId; });

            if (null != cmatch) { 

                if (dTime == '') { dTime = cmatch.matchLongTime; }
                if (new Date(dTime) > new Date(cmatch.matchLongTime)) {
                    dTime = cmatch.matchLongTime;
                }


                if (new Date(cmatch.matchLongTime) > new Date(lotteryTime)) {
                    lotteryTime = cmatch.matchLongTime;
                    issue = cmatch.issue;
                    num = cmatch.matchNumber.substring(2, 5);
                }
            }

            
            var smatch = {
                OddId: -1,
                SelectedMatchId: matchId,
                Dan: false,
                SelectedJCHadOddId: -1,
                SelectedJCHHadOddId: -1,
                SelectedJCHAFUOddId: -1,
                SelectedJCHadOdds: "",
                SelectedJCHHadOdds: "",
                SelectedJCHAFUOdds: ""
            }
            var spans = $(n).children("td:eq(4)").children("span");

            $.each(spans, function (j, k) {
                var result = parseInt($(k).attr("result"));
                var bOddId = $(k).attr("bOddId");
                if (result <= 3) {
                    smatch.SelectedJCHadOddId = bOddId;
                    smatch.SelectedJCHadOdds += result + ",";
                } else {
                    smatch.SelectedJCHHadOddId = bOddId;
                    smatch.SelectedJCHHadOdds += result + ",";
                }
            });

            if (smatch.SelectedJCHadOdds.length > 0 || smatch.SelectedJCHHadOdds.length > 0) {
                smatchs.push(smatch);
            }

        });
        //saveOdd.LotteryTime = new Date((lotteryTime.getTime() + 1000 * 60 * 120));
        
        saveOdd.LotteryTime = lotteryTime;
        saveOdd.OrderString = issue + " " + num;
        saveOdd.OddSelectedMatchList = smatchs;
        saveOdd.DocumentaryCutoffTime = dTime;
        return saveOdd;
    }



    function GetAllAppUser() {
        AjaxData("/AppUser/GetAllUser", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                AllAppUser = d.data;
                GetRealTimeData();
                //var ss = '';
                //$.each(d.data, function (i, n) {
                //    if (i == 0) {
                //        ss += '<option value="' + n.id + '" selected="selected">' + n.text + '</option>';
                //    } else {
                //        ss += '<option value="' + n.id + '">' + n.text + '</option>';
                //    }
                //});
                //$("#selectAppUser").html(ss);
                //$("#selectAppUser").select2({ width: 100 }).trigger("change");
            }
        });
    }

    function GetNoneChildrenSites() {
        AjaxData("/Site/GetNoneChildrenSites", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                var ss = '';
                $.each(d.data.OrderBy(function (x) { return x.name}), function (i, n) {
                    if (i == 0) {
                        ss += '<option value="' + n.id + '" selected="selected">' + n.name + '</option>';
                    } else {
                        ss += '<option value="' + n.id + '">' + n.name + '</option>';
                    }
                });
                $("#selectSite").html(ss);
                $("#selectSite").select2({ width: 100 }).trigger("change");
            }
        })
    }

    function AverageCapital(money) {
        var arr = betDetailOdds.Where(function (x) { return x.Checked == true; });
        if (undefined != arr && null != arr && arr.length > 0) {
            money = money / 2;
            var count = money;
            var k = 0;
            for (var i = 0; i < arr.length; i++) {
                k += (1 / arr[i].SP);
            }
            k = 1 / k;
            $.each(arr, function (i, n) {
                n.BetCount = Math.round(money * k / n.SP);
                count = count - n.BetCount;
            });

            if (count != 0) {
                var index = 0;
                if (count > 0) {
                    index = 1;
                    for (var i = count; i > 0; i -= index) {
                        var valueArr = new Array();
                        var ci = 0;
                        var cab = 1000000000;
                        var agvBonus = arr.Average(function (x) { return x.Bonus; });
                        $.each(arr, function (t, n) {
                            var c = DeepCopy(arr);
                            c[t].BetCount += index;
                            c[t].Bonus = c[t].BetCount * 2 * c[t].SP;
                            var cAvgBonus = c.Average(function (x) { return x.Bonus; });
                            var cabs = 0;
                            $.each(c, function (e, r) {
                                cabs += Math.abs(r.Bonus - cAvgBonus);
                            });
                            if (cab > cabs) {
                                cab = cabs;
                                ci = t;
                            }
                        });

                        arr[ci].BetCount += index;
                        arr[ci].Bonus = arr[ci].BetCount * 2 * arr[ci].SP;
                    }
                } else {
                    index = -1;
                    for (var i = count; i < 0; i -= index) {
                        var valueArr = new Array();
                        var ci = 0;
                        var cab = 1000000000;
                        var agvBonus = arr.Average(function (x) { return x.Bonus; });
                        $.each(arr, function (t, n) {
                            var c = DeepCopy(arr);
                            c[t].BetCount += index;
                            c[t].Bonus = c[t].BetCount * 2 * c[t].SP;
                            var cAvgBonus = c.Average(function (x) { return x.Bonus; });
                            var cabs = 0;
                            $.each(c, function (e, r) {
                                cabs += Math.abs(r.Bonus - cAvgBonus);
                            });
                            if (cab > cabs) {
                                cab = cabs;
                                ci = t;
                            }
                        });

                        arr[ci].BetCount += index;
                        arr[ci].Bonus = arr[ci].BetCount * 2 * arr[ci].SP;
                    }

                }


            }

            //$("#oddArrString").val(JSON.stringify(arr));
        }
    }

    ///深度拷贝数组
    function DeepCopy(o) {
        if (o instanceof Array) {
            var n = [];
            for (var i = 0; i < o.length; ++i) {
                n[i] = DeepCopy(o[i]);
            }
            return n;

        } else if (o instanceof Object) {
            var n = {}
            for (var i in o) {
                n[i] = DeepCopy(o[i]);
            }
            return n;
        } else {
            return o;
        }
    }

    function GetAnalystSelectedMatchsByMatchIds(ids) {
        var postData = {
            matchIds: ids
        }
        $("#analyst_selected_list").empty();
        AjaxData("/AnalystSelectedMatch/GetAnalystSelectedMatchsByMatchIds", postData, "Post", "", function (d) {
            if (undefined != d && d.success) {
                AnalystSelectedMatchs = d.data;

                $.each(d.data.OrderBy(function (x) { return x.issue }).ThenBy(function (x) { return x.weekName.substring(2, 5) }), function (i, n) {
                  

                    var ss = '<tr style="display: table-row;" matchId="' + n.matchId + '">';
                    ss += '<td class="center" >' + n.detailSelectedContentsList[0].weekName + '</td >';
                    //ss += '<td class="center">' + match.cutPayOutRate + '</td>';
                    ss += '<td class="center">';
                    var user = AllAppUser.FirstOrDefault(function (x) { return x.id == n.createAppUserId });
                    var bd = n.detailSelectedContentsList.Where(function (x) { return x.fixOdds == ""; });
                    $.each(bd, function (j, k) {

                        ss += k.selectedOdds;
                        if (j < bd.length - 1) {
                            ss += '+';
                        } else {
                            ss += "<br/>";
                        }

                        var fselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                        var selector;
                        if (user.colorName == 1) {
                            selector = fselector.children("span");
                            selector.addClass("span-red");
                        } else if (user.colorName == 2) {
                            selector = fselector.children("span").children("span");
                            selector.addClass("span-green");
                        } else {
                            selector = fselector.children("span").children("span").children("span");
                            selector.addClass("span-blue");
                        }
                        if (k.goodLevel == 1) {
                            selector.addClass("border-solid");
                        } else {
                            selector.addClass("border-double");
                        }
                       
                    });

                    var rd = n.detailSelectedContentsList.Where(function (x) { return x.fixOdds != ""; });
                    $.each(rd, function (j, k) {

                        ss += k.selectedOdds;
                        if (j < rd.length - 1) {
                            ss += '+';
                        }


                        var fselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                        var selector;
                        if (user.colorName == 1) {
                            selector = fselector.children("span");
                            selector.addClass("span-red");
                        } else if (user.colorName == 2) {
                            selector = fselector.children("span").children("span");
                            selector.addClass("span-green");
                        } else {
                            selector = fselector.children("span").children("span").children("span");
                            selector.addClass("span-blue");
                        }
                        if (k.goodLevel == 1) {
                            selector.addClass("border-solid");
                        } else {
                            selector.addClass("border-double");
                        }
                        //$("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']").addClass("border-selected");
                        

                    });

                    //SelectedMatchs.push(smatch);
                    ss += '</td>';

                    //ss += '<td class="center">' + CreateBookMarkOption(n.bookMarksString) + '</td>';
                    ss += '<td class="center" >' + n.sp + '</td >';
                    ss += '<td class="center" >' + n.resultChance + '</td >';
                    ss += '<td class="center" ><a title="' + n.remark + '" href="#" matchId="' + n.matchId + '" class="editRemark"  canEdit="' + (currenrUser.id == n.createAppUserId ? true : false) + '">' + (n.remark == "" ? "" : n.remark.substring(0, 2)) + '</a></td >';
                    //ss += '  <td class="center"><a title="删除" href="#" matchId="' + n.matchId + '" class="deleteSelectedMatch"><i class="glyphicon glyphicon-remove"></i></a></td>';
                    ss += '  </tr >';

                    $("#analyst_selected_list").append(ss);
                });
            }
        });
    }


    function GetSelectedMatchOddDataByMatchIds(ids) {
        var postData = {
            ids: ids
        }
        $("#analyst_selected_list").empty();
        AjaxData("/Odd/GetSelectedMatchOddDataByMatchIds", postData, "Post", "", function (d) {
            if (undefined != d && d.success) {
                if (d.data == null) { return; }
                $.each(d.data, function (i, n) {


                    if (n.betCount < 1500) {

                    } else if (n.betCount >= 1500 && n.betCount < 5000) {
                        $("#matchData-tbody tr td[matchId='" + n.matchId + "'][result='" + n.result + "']>span>span>span").addClass("countColor1");
                    } else if (n.betCount >= 5000 && n.betCount < 15000) {
                        $("#matchData-tbody tr td[matchId='" + n.matchId + "'][result='" + n.result + "']>span>span>span").addClass("countColor2");
                    } else {
                        $("#matchData-tbody tr td[matchId='" + n.matchId + "'][result='" + n.result + "']>span>span>span").addClass("countColor3");
                    }

                });
               
                GetOddBySelectedMatchIds(ids);
            }
        });
    }



    function CreateBookMarkOption(bookMarks) {
        var s = "";
        if (undefined == bookMarks || null == bookMarks || "" == bookMarks) {
        } else {
            var arr = bookMarks.split(',');
            $.each(arr, function (i, n) {
                var bookMark = AllBookMarks.FirstOrDefault(function (x) { return x.id == parseInt(n) });
                s += '<button class="btn btn-minier" style="background-color:' + bookMark.markColor + ' !important;border-color:' + bookMark.markColor + ' !important;">' + bookMark.markName + '</button>';
            });
        }
        return s;
    }

    function WriteMatchCategoryPanel() {
        if (AllMatchs.length > 0) {
            //$("#SPDiv").empty();
            $("#DateDiv").empty();
            $("#RQDiv").empty();
            $("#LeagueDiv").empty();
            //$.each(OddValueArr, function (i, n) {
            //    var count = AllMatchs.Count(function (x) {
            //        var brqOdd = x.JCHadOddsList.SingleOrDefault(function (p) { return p.fixedOdds == "" && p.releaseTime == x.JCHadOddsList.Where(function (z) { return z.fixedOdds == "" }).Max(function (z) { return z.releaseTime; }) });
            //        return
            //    })
            //});

            var wMatchGroup = AllMatchs.GroupBy(function (x) { return x.issue; });
            var s = '';
            $.each(wMatchGroup, function (i, n) {
                s += '<label class="pos-rel" data-stopPropagation="true"><input class="ace DateChk" type= "checkbox" checked="checked" value="' + n.GroupValue + '"> <span class="lbl">' + getMyDay(new Date(n.GroupValue)) + '(' + (n.length / 2) + '场)</span></label >&nbsp;&nbsp;&nbsp;&nbsp;';
            });
            $("#DateDiv").html(s);


            var rqMatchGroup = AllMatchs.GroupBy(function (x) {
                //if (null == x.jcHadOddsList) { return null; }

                return x.fixedOdds;
            });
            var ss = '';
            $.each(rqMatchGroup, function (i, n) {
                //if (n.GroupValue != "-1" && n.GroupValue != "+1") { return true; }
                ss += '<label class="pos-rel" data-stopPropagation="true"><input class="ace RQChk" type= "checkbox" checked="checked" value="' + n.GroupValue + '"> <span class="lbl">' + n.GroupValue + '(' + n.length + '场)</span></label >&nbsp;&nbsp;&nbsp;&nbsp;';
            });
            $("#RQDiv").html(ss);

            var leaugeMatchGroup = AllMatchs.GroupBy(function (x) {
                return x.tournamentName;
            });
            var ss = '';
            $.each(leaugeMatchGroup, function (i, n) {

                ss += '<label class="pos-rel" data-stopPropagation="true"><input class="ace LeagueChk" type= "checkbox" checked="checked" value="' + n.GroupValue + '"> <span class="lbl">' + n.GroupValue + '(' + n.length + '场)</span></label >&nbsp;&nbsp;&nbsp;&nbsp;';
                if ((i + 1) % 3 == 0) {
                    ss += '<br/>';
                }
            });
            $("#LeagueDiv").html(ss);
        }
    }

    function GetMatchDataByIssue(issue) {
        var url = "/JCMatch/GetMatchsByIssue?issue=" + issue;

        AjaxData(url, null, "Get", "", function (d) {
            if (d.success) {
                AllMatchs = d.data;
                WriteTableData(d.data);
                ids = d.data.Select(function (x) { return x.matchId; });
            }
        });

    }

    function GetAllIssues() {
        var url = "/JCMatch/GetAllIssue";
        AjaxData(url, null, "Get", "", function (d) {
            if (d.success) {
                var ss = "";
                $.each(d.data, function (i, n) {
                    ss += '<option value="' + n + '" >' + n + '</option>';
                });
                $('#GameNumberList').html(ss);
                $("#GameNumberList").select2();
            }
        });
    }


    function GetRealTimeData() {
        var url = "/JCMatch/GetNoFinishedMatch";
        AjaxData(url, null, "Get", "", function (d) {
            if (d.success) {
                AllMatchs = d.data;
                WriteTableData(d.data);
                ids = d.data.Select(function (x) { return x.matchId; });
            }
        });
    }


    function CheckRealResult(wholeScore, fixOdd, result) {
        if (null != wholeScore && undefined != wholeScore && wholeScore.length > 0 && fixOdd != "") {
            var scores = wholeScore.split(':');
            var r = parseInt(scores[0]) - parseInt(scores[1]) + parseInt(fixOdd);
            if ((r > 0 && result == 3) || (r == 0 && result == 1) || (r < 0 && result == 0)) {
                return true;
            } else {
                return false;
            }

        } else {
            return false;
        }
    }

    function getMyDay(date) {
        var week;
        if (date.getDay() == 0) week = "星期日"
        if (date.getDay() == 1) week = "星期一"
        if (date.getDay() == 2) week = "星期二"
        if (date.getDay() == 3) week = "星期三"
        if (date.getDay() == 4) week = "星期四"
        if (date.getDay() == 5) week = "星期五"
        if (date.getDay() == 6) week = "星期六"
        return week;
    }




    function GetSelectedOddContent(n) {
        var s = '';
        if (n.homeCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">胜</span>';
        }
        if (n.drawCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">平</span>';
        }
        if (n.loseCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">负</span>';
        }
        if (s.length > 0) { s += '<br/>'; }
        if (n.letBallHomeCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">让胜</span>';
        }
        if (n.letBallDrawCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">让平</span>';
        }
        if (n.letBallLoseCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">让负</span>';
        }

        return s;

    }

    function CaculateMatchResult(hostScore, guestScore, fixOdd) {
        if (hostScore == -1 || guestScore == -1) { return -1; }
        var result = hostScore - guestScore + fixOdd;
        if (result > 0) {
            return 3;
        } else if (result == 0) {
            return 1;
        }
        else {
            return 0;
        }
    }

    function WriteTableData(d) {
        $('#matchData-tbody').empty();
        if (undefined == d || {} == d) { return; }
        var ss = "";

        var preMatchId = 0;
        var className = "";
        $.each(d, function (i, n) {

            if (i == 0) { preMatchId = n.matchId; } else {
                if (n.matchId == preMatchId) {

                } else {
                    preMatchId = n.matchId;
                    if (className == "") {
                        className = "background-tr-color";
                    } else {
                        className = "";
                    }

                }
            }



            ss += '<tr MatchId="' + n.matchId + '"  class="' + className + '"  League="' + n.tournamentName + '" Issue="' + n.issue + '" FiveHundredMatchId="' + n.fiveHundredMatchId + '" FixOdds="' + n.fixedOdds + '"  CanSingleBet="' + n.canSingleBet + '"    >';

            ss += '<td class="center">' + (n.index) + (n.canSingleBet == "1" ? '<div style="padding:0;margin-top:-8px;margin-left:-3px;border: 0;height:0px;width:0px;float:left"><font style= "color:red;font-weight:bold;font-size:10px;" >单</font ></div >' : '') + '</td>';
            ss += '<td class="center WuBaiID">' + n.fiveHundredMatchId + '</td>';
            ss += '<td class="center"><span class="showDesc" matchId="' + n.matchId + '">' + n.matchNumber + '</span></td>';

            if (n.fixedOdds == null || n.fixedOdds == "") {  // 不让球
                ss += '<td class="center">' + n.tournamentName + '</td>';
            } else {
                ss += '<td class="center"><a style="color:orange;" target="_blank" href="http://liansai.500.com/zuqiu-' + n.fiveSeasonId + '/" >' + n.tournamentName + '</a></td>';
            }

            ss += '<td class="center DateTime">' + n.matchTime + '</td>';

            if (n.fixedOdds == null || n.fixedOdds == "") {
                ss += '<td class="center"><a data-teamid="' + n.homeTeamId + '" data-teamname="' + n.homeTeamName + '"  href="../TeamPlayInfo?teamId=' + n.homeTeamId + '&matchId=' + n.fiveHundredMatchId + '"  target="_blank" title="自身页面详细信息">' + n.homeTeamName + '</a></td>';
                ss += '<td class="center"><a data-teamid="' + n.awayTeamId + '" data-teamname="' + n.awayTeamName + '"  href="../TeamPlayInfo?teamId=' + n.awayTeamId + '&matchId=' + n.fiveHundredMatchId + '"  target="_blank" title="自身页面详细信息">' + n.awayTeamName + '</a></td>';
            } else {
                ss += '<td class="center"><a style="color:orange;" data-teamid="' + n.homeTeamId + '" href="http://liansai.500.com/team/' + n.homeTeamId + '/" target="_blank" title="500页面详细信息">' + n.homeTeamName + '</a></td>';
                ss += '<td class="center"><a style="color:orange;" data-teamid="' + n.awayTeamId + '" href="http://liansai.500.com/team/' + n.awayTeamId + '/" target="_blank" title="500页面详细信息">' + n.awayTeamName + '</a></td>';
            }

            if (n.fixedOdds != "") {
                ss += '<td class="center Score"><a style="color:orange;" class="linkTo500"  matchId="' + n.fiveHundredMatchId + '" href="http://odds.500.com/fenxi/shuju-' + n.fiveHundredMatchId+'">析</a></td>';

            } else {
                ss += '<td class="center Score">' + (null == n.wholeScore ? '' : n.wholeScore) + '</td>';
            }
            ss += '<td class="center">' + n.fixedOdds + '</td>';
            if (null == n.homeOdds) {
                ss += '<td class="center winOdd"></td>';
                ss += '<td class="center drawOdd"></td>';
                ss += '<td class="center loseOdd"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center OddCount"></td>';
                ss += '<td class="center YiJia"></td>';
                ss += '<td class="center YiJia"></td>';
                ss += '<td class="center YiJia"></td>';
                ss += '<td class="center NiHe"></td>';
                ss += '<td class="center NiHe"></td>';
                ss += '<td class="center NiHe"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center CeLue"></td>';
                ss += '<td class="center CeLue"></td>';
                ss += '<td class="center CeLue"></td>';
                ss += '<td class="center KeKao"></td>';
                ss += '<td class="center KeKao"></td>';
                ss += '<td class="center KeKao"></td>';
            } else {

                var arr = null == n.wholeScore ? [-1, -1] : n.wholeScore.split(':');
                var result = CaculateMatchResult(parseInt(arr[0]), parseInt(arr[1]), n.fixedOdds == "" ? 0 : parseInt(n.fixedOdds));

                ss += '<td class="center odd winOdd   ' + (result == 3 ? "right-result" : "") + '" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" bOddId="' + n.bOddId + '" payReturn="' + n.jcWinPayOut + '" result="' + (n.fixedOdds == "" ? 1 : 4) + '" matchNumber="' + n.matchNumber + '"   chance="' + n.myCutWinChance + '"><span><span><span class="default-span">' + n.homeOdds + '</span></span></span></td>';
                ss += '<td class="center odd drawOdd   ' + (result == 1 ? "right-result" : "") + '" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" bOddId="' + n.bOddId + '"  payReturn="' + n.jcDrawPayOut + '" result="' + (n.fixedOdds == "" ? 2 : 5) + '" matchNumber="' + n.matchNumber + '"  chance="' + n.myCutDrawChance + '"><span><span><span class="default-span">' + n.drawOdds + '</span></span></span></td>';
                ss += '<td class="center odd loseOdd   ' + (result == 0 ? "right-result" : "") + '" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" bOddId="' + n.bOddId + '" payReturn="' + n.jcLosePayOut + '" result="' + (n.fixedOdds == "" ? 3 : 6) + '" matchNumber="' + n.matchNumber + '"  chance="' + n.myCutLoseChance + '"><span><span><span class="default-span">' + n.awayOdds + '</span></span></span></td>';
                ss += '<td class="center">' + (null == n.cutPayOutRate ? '' : n.cutPayOutRate) + '</td>';
                ss += '<td class="center">' + (null == n.avgEuropWinOdd ? '' : n.avgEuropWinOdd) + '</td>';
                ss += '<td class="center">' + (null == n.avgEuropDrawOdd ? '' : n.avgEuropDrawOdd) + '</td>';
                ss += '<td class="center">' + (null == n.avgEuropLoseOdd ? '' : n.avgEuropLoseOdd) + '</td>';
                ss += '<td class="center OddCount">' + (n.baseDataCount == 0 ? "" : n.baseDataCount) + '</td>';
                ss += '<td class="center YiJia">' + n.myCutWinDeviate + '</td>';
                ss += '<td class="center YiJia">' + n.myCutDrawDeviate + '</td>';
                ss += '<td class="center YiJia">' + n.myCutLoseDeviate + '</td>';
                ss += '<td class="center FanHuan"   matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcWinPayOut + '" result="' + (n.fixedOdds == "" ? 1 : 4) + '"><span><span><span class="default-span">' + n.jcWinPayOut + '</span></span></span></td>';
                ss += '<td class="center FanHuan" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcDrawPayOut + '" result="' + (n.fixedOdds == "" ? 2 : 5) + '"><span><span><span class="default-span">' + n.jcDrawPayOut + '</span></span></span></td>';
                ss += '<td class="center FanHuan" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcLosePayOut + '" result="' + (n.fixedOdds == "" ? 3 : 6) + '"><span><span><span class="default-span">' + n.jcLosePayOut + '</span></span></span></td>';
                ss += '<td class="center NiHe">' + n.myCutWinChance + '</td>';
                ss += '<td class="center NiHe">' + n.myCutDrawChance + '</td>';
                ss += '<td class="center NiHe">' + n.myCutLoseChance + '</td>';
                ss += '<td class="center CeLue">' + (n.winCoefficientOfStrategy == 0 ? "" : n.winCoefficientOfStrategy) + '</td>';
                ss += '<td class="center CeLue">' + (n.drawCoefficientOfStrategy == 0 ? "" : n.drawCoefficientOfStrategy)+ '</td>';
                ss += '<td class="center CeLue">' + (n.loseCoefficientOfStrategy == 0 ? "" : n.loseCoefficientOfStrategy)+ '</td>';
                ss += '<td class="center KeKao">' + (n.winReliability == 0 ? "" : n.winReliability) + '</td>';
                ss += '<td class="center KeKao">' + (n.drawReliability == 0 ? "" : n.drawReliability)+ '</td>';
                ss += '<td class="center KeKao">' + (n.loseReliability == 0 ? "" : n.loseReliability) + '</td>';
            }
            ss += '</tr>';

        });

        $('#matchData-tbody').html(ss);




        WriteMatchCategoryPanel();
        var ids = d.Select(function (x) { return x.matchId }).Distinct();
        GetAnalystSelectedMatchsByMatchIds(ids);
        GetSelectedMatchOddDataByMatchIds(ids);
        
        $("#match-table").chromatable({
            width: "100%",
            height: "780px",
            scrolling: "yes"
        });

        $("#hiddenColumnBtn").trigger("click");
    }


    var trcompare = function (prop) {
        return function (obj1, obj2) {
            var val1 = parseFloat($(obj1).children("td").eq(prop).html());
            var val2 = parseFloat($(obj2).children("td").eq(prop).html());
            if (val1 < val2) {
                return -1;
            } else if (val1 > val2) {
                return 1;
            } else {
                return 0;
            }
        }
    }
    var trcompareDesc = function (prop) {
        return function (obj1, obj2) {
            var val1 = parseFloat($(obj1).children("td[class='" + prop + "']").eq(0).html());
            var val2 = parseFloat($(obj2).children("td[class='" + prop + "']").eq(0).html());
            if (val1 < val2) {
                return 1;
            } else if (val1 > val2) {
                return -1;
            } else {
                return 0;
            }
        }
    }

    function MatchSortCompareDesc() {
        return function (obj1, obj2) {
            if (obj1 == null || obj2 == null) { return 0; }
            var row1Values = [{
                odd: parseFloat($(obj1).find("td.winOdd").eq(0).html() == "" ? "0" : $(obj1).find("td.winOdd").eq(0).html()),
                celue: parseFloat($(obj1).find("td.CeLue").eq(0).html() == "" ? "0" : $(obj1).find("td.CeLue").eq(0).html()),
                kekao: parseFloat($(obj1).find("td.KeKao").eq(0).html() == "" ? "0" : $(obj1).find("td.KeKao").eq(0).html())
            }, {
                odd: parseFloat($(obj1).find("td.drawOdd").eq(0).html() == "" ? "0" : $(obj1).find("td.drawOdd").eq(0).html()),
                celue: parseFloat($(obj1).find("td.CeLue").eq(1).html() == "" ? "0" : $(obj1).find("td.CeLue").eq(1).html()),
                kekao: parseFloat($(obj1).find("td.KeKao").eq(1).html() == "" ? "0" : $(obj1).find("td.KeKao").eq(1).html())
            }, {
                odd: parseFloat($(obj1).find("td.loseOdd").eq(0).html() == "" ? "0" : $(obj1).find("td.loseOdd").eq(0).html()),
                celue: parseFloat($(obj1).find("td.CeLue").eq(2).html() == "" ? "0" : $(obj1).find("td.CeLue").eq(2).html()),
                kekao: parseFloat($(obj1).find("td.KeKao").eq(2).html() == "" ? "0" : $(obj1).find("td.KeKao").eq(2).html())
            }];

            var row2Values = [{
                odd: parseFloat($(obj2).find("td.winOdd").eq(0).html() == "" ? "0" : $(obj2).find("td.winOdd").eq(0).html()),
                celue: parseFloat($(obj2).find("td.CeLue").eq(0).html() == "" ? "0" : $(obj2).find("td.CeLue").eq(0).html()),
                kekao: parseFloat($(obj2).find("td.KeKao").eq(0).html() == "" ? "0" : $(obj2).find("td.KeKao").eq(0).html())
            }, {
                odd: parseFloat($(obj2).find("td.drawOdd").eq(0).html() == "" ? "0" : $(obj2).find("td.drawOdd").eq(0).html()),
                celue: parseFloat($(obj2).find("td.CeLue").eq(1).html() == "" ? "0" : $(obj2).find("td.CeLue").eq(1).html()),
                kekao: parseFloat($(obj2).find("td.KeKao").eq(1).html() == "" ? "0" : $(obj2).find("td.KeKao").eq(1).html())
            }, {
                odd: parseFloat($(obj2).find("td.loseOdd").eq(0).html() == "" ? "0" : $(obj2).find("td.loseOdd").eq(0).html()),
                celue: parseFloat($(obj2).find("td.CeLue").eq(2).html() == "" ? "0" : $(obj2).find("td.CeLue").eq(2).html()),
                kekao: parseFloat($(obj2).find("td.KeKao").eq(2).html() == "" ? "0" : $(obj2).find("td.KeKao").eq(2).html())
            }];

            var a = row1Values.OrderByDescending(function (x) { return x.celue })[0];
            var b = row2Values.OrderByDescending(function (x) { return x.celue })[0];


            if (a.celue == 0 && b.celue == 0) {
                var val1 = parseFloat($(obj1).children("td").eq(0).html());
                var val2 = parseFloat($(obj2).children("td").eq(0).html());
                if (val1 < val2) {
                    return 1;
                } else if (val1 > val2) {
                    return -1;
                } else {
                    return 0;
                }
            }
            else {
                if (a.celue < b.celue) {
                    return -1;
                } else if (a.celue > b.celue) {
                    return 1;
                } else {
                    if (a.kekao < b.kekao) {
                        return -1;
                    } else if (a.kekao > b.kekao) {
                        return 1;
                    } else {
                        if (a.odd < a.odd) {
                            return 1;
                        } else if (a.odd > b.odd) {
                            return -1;
                        } else {
                            return 0;
                        }
                    }
                }
            }
        }
    }

    var compare = function (prop) {
        return function (obj1, obj2) {
            var val1 = obj1[prop];
            var val2 = obj2[prop];
            if (val1 < val2) {
                return -1;
            } else if (val1 > val2) {
                return 1;
            } else {
                return 0;
            }
        }
    }
    var compareDesc = function (prop) {
        return function (obj1, obj2) {
            var val1 = obj1[prop];
            var val2 = obj2[prop];
            if (val1 < val2) {
                return 1;
            } else if (val1 > val2) {
                return -1;
            } else {
                return 0;
            }
        }
    }

    function WriteOddTableData() {
        var ss = '';
        $("#selected_detailOdd_list").empty();
        $.each(betDetailOdds, function (i, n) {
            ss += '<tr>';
            ss += '<td class="center">' + (n.Index + 1) + '</td>';
            ss += '<td class="center">' + n.Content + '</td>';
            ss += '<td class="center">' + Math.round(n.PayReturn * 10000) / 100 + '%</td>';
            ss += '<td class="center"> ' + n.SP + '</td>';
            ss += '<td class="center"><input class="count" style="width:70px;" type="text" value="' + n.BetCount + '"></td>';
            ss += '<td class="center"><a title="删除" href="#" index="' + n.Index + '" class="deleteCreatedOdd"><i class="glyphicon glyphicon-remove"></i></a></td>';
            ss += '</tr>';
        });
        $("#selected_detailOdd_list").html(ss);
    }
    function getContentString(odd) {
        var s = "";
        $.each(odd, function (i, n) {
            //s += '<span class="label label-warning arrowed-in-right arrowed" style="margin-bottom:1px !important;">' + n.WeekName + '-' + ((n.FixOdds == "0" ? "" : "让" + n.FixOdds) + SelectedResultObj.FirstOrDefault(function (x) { return x.id == n.SelectedResult }).text.replace("让", "")) + '-' + n.SelectedOdds + '</span>';

            s += '<span class="label label-warning arrowed-in-right arrowed" style="margin-bottom:1px !important;">' + n.WeekName + '-'  + SelectedResultObj.FirstOrDefault(function (x) { return x.id == n.SelectedResult }).text + '-' + n.SelectedOdds + '</span>';
            s += '<br/>';
        });
        return s;
    }


    function MakeBettingDanGuanDetails(smatchs) {
        var odds = new Array();
        for (var i = 0; i < smatchs.length; i++) {
            for (var c = 0; c < smatchs[i].selectedOdds.length; c++) {
                odds.push([smatchs[i].selectedOdds[c]]);
            }
        }
        return odds;
    }

    function MakeBetting2X1Details(smatchs) {
        var odds = new Array();
        var danMatch = smatchs.Where(function (x) { return x.dan == true; });
        if (danMatch.length > 0) {
            noDanMatch = smatchs.Where(function (x) { return x.dan == false; });

            for (var i = 0; i < danMatch.length; i++) {
                for (var j = i + 1; j < danMatch.length; j++) {
                    if (danMatch[i].matchId != danMatch[j].matchId) {
                        for (var c = 0; c < danMatch[i].selectedOdds.length; c++) {
                            for (var b = 0; b < danMatch[j].selectedOdds.length; b++) {

                                var singleArr = new Array();
                                singleArr.push(danMatch[i].selectedOdds[c]);
                                singleArr.push(danMatch[j].selectedOdds[b]);
                                odds.push(singleArr);
                            }
                        }
                    }
                }
                for (var j = 0; j < noDanMatch.length; j++) {
                    if (danMatch[i].matchId != noDanMatch[j].matchId) {
                        for (var c = 0; c < danMatch[i].selectedOdds.length; c++) {
                            for (var b = 0; b < noDanMatch[j].selectedOdds.length; b++) {

                                var singleArr = new Array();
                                singleArr.push(danMatch[i].selectedOdds[c]);
                                singleArr.push(noDanMatch[j].selectedOdds[b]);
                                odds.push(singleArr);
                            }
                        }
                    }
                }
            }
        } else {
            for (var i = 0; i < smatchs.length; i++) {
                for (var j = i + 1; j < smatchs.length; j++) {
                    if (smatchs[i].matchId != smatchs[j].matchId) {
                        for (var c = 0; c < smatchs[i].selectedOdds.length; c++) {
                            for (var b = 0; b < smatchs[j].selectedOdds.length; b++) {
                                var singleArr = new Array();
                                singleArr.push(smatchs[i].selectedOdds[c]);
                                singleArr.push(smatchs[j].selectedOdds[b]);
                                odds.push(singleArr);
                            }
                        }
                    }

                }
            }

        }
        return odds;

    }

    function MakeBetting3X1Details(smatchs) {
        if (smatchs.length < 3) {
            return [];
        }
        var odds = new Array();
        for (var a = 0; a < smatchs.length; a++) {
            var d = smatchs[a];
            for (var i = 0; i < d.selectedOdds.length; i++) {
                for (var b = a + 1; b < smatchs.length; b++) {
                    var e = smatchs[b];
                    for (var j = 0; j < e.selectedOdds.length; j++) {
                        for (var c = b + 1; c < smatchs.length; c++) {

                            var f = smatchs[c];
                            for (var k = 0; k < f.selectedOdds.length; k++) {
                                var singleArr = new Array();
                                singleArr.push(d.selectedOdds[i]);
                                singleArr.push(e.selectedOdds[j]);
                                singleArr.push(f.selectedOdds[k]);
                                odds.push(singleArr);

                            }
                        }
                    }
                }
            }
        }
        return odds;
    }

</script>


